package com.alfredo.android.appcaja.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.alfredo.android.appcaja.R;
import com.alfredo.android.appcaja.model.Orden;

public class OrdenesAdapter extends ArrayAdapter<Orden> 
{	
	private class ViewHolder
	{
		TextView tvLiCgi;
		TextView tvLiNExpediente;
		TextView tvLiCausanteBeneficiario;
	}
	
	public OrdenesAdapter(Context context)
	{
		super(context, -1);
	}
	
	public OrdenesAdapter(Context context, ArrayList<Orden> ordenes)
	{
		super(context, -1, ordenes);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		Orden orden = getItem(position);
		ViewHolder viewHolder;
		
		if(convertView == null)
		{
			LayoutInflater inflater = LayoutInflater.from(getContext());
			convertView = inflater.inflate(R.layout.orden_list_item, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.tvLiCgi = (TextView) convertView.findViewById(R.id.tvLiCgi);
			viewHolder.tvLiNExpediente = (TextView) convertView.findViewById(R.id.tvLiNExpediente);
			viewHolder.tvLiCausanteBeneficiario = (TextView) convertView.findViewById(R.id.tvLiCausanteBeneficiario);
			convertView.setTag(viewHolder);
		}
		else
		{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		viewHolder.tvLiCgi.setText(String.valueOf(orden.getCgi()));
		viewHolder.tvLiNExpediente.setText(String.valueOf(orden.getNroExpediente()));
		viewHolder.tvLiCausanteBeneficiario.setText(orden.getCausanteBeneficiario());
		
		return convertView;
	}
}
